/**
 * File name: MatrixDistanceMeter.java Author: Willard Wang Create date: Aug 24,
 * 2013
 */
package edu.sjtu.se.prophet.cluster;

import java.util.HashMap;

import org.apache.log4j.Logger;

/**
 * @author deathspeeder
 * 
 */
public class MatrixArrayDistanceMeter implements DistanceMeter {
    private static Logger logger = Logger.getLogger(MatrixArrayDistanceMeter.class);

    private Point[] points;
    private byte[][] distanceMatrix;

    public MatrixArrayDistanceMeter(Point[] points, byte[][] distanceMatrix) {
        this.points = points;
        this.distanceMatrix = distanceMatrix;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * edu.sjtu.se.prophet.cluster.DistanceMeter#distance(edu.sjtu.se.prophet
     * .cluster.Point, edu.sjtu.se.prophet.cluster.Point)
     */
    @Override
    public int distance(Point a, Point b) {
        int aIndex = 0;
        int bIndex = 0;
        for (int i = 0; i < points.length; i++) {
            if (a.equals(points[i]))
                aIndex = i;
            if (b.equals(points[i]))
                bIndex = i;
        }
        return distanceMatrix[aIndex][bIndex];
    }

}
